Open
Conversation
sharkich
requested changes
Mar 17, 2023
|
|
||
| const startDateStr = '31 Jan 2022'; | ||
| const endDateStr = '03 Feb 2021' | ||
| function dateDiff(startDateStr, endDateStr, unit = 'seconds') { |
Owner
There was a problem hiding this comment.
no default values for startDateStr and startDateStr
Comment on lines
+10
to
+23
| switch (unit) { | ||
| case 'seconds' : | ||
| result = result / 1000; | ||
| break; | ||
| case "minutes" : | ||
| result = result / 60000; | ||
| break; | ||
| case "hours" : | ||
| result = result / (1000 * 60 * 60); | ||
| break; | ||
| case "days" : | ||
| result = result / (1000 * 60 * 60 * 24); | ||
| break; | ||
| } |
Owner
There was a problem hiding this comment.
To avoid copy/paste let's create an object with keys - unit and values - numbers.
| function dateDiff(startDateStr, endDateStr, unit = 'seconds') { | ||
| const startDate = new Date(startDateStr); | ||
| const endDate = new Date(endDateStr); | ||
| let result = Math.abs(endDate - startDate); |
| let sum = 0; | ||
|
|
||
| for (i = 1; i <= number; i++) { | ||
| if (i % 2 == 1) |
Owner
There was a problem hiding this comment.
can we avoid checking every odd number?
sharkich
requested changes
Mar 22, 2023
|
|
||
| dateDiff(endDateStr, startDateStr, 'days'); | ||
|
|
||
| console.log(result); |
Comment on lines
+20
to
+33
| // switch (unit) { | ||
| // case 'seconds' : | ||
| // result = result / 1000; | ||
| // break; | ||
| // case "minutes" : | ||
| // result = result / 60000; | ||
| // break; | ||
| // case "hours" : | ||
| // result = result / (1000 * 60 * 60); | ||
| // break; | ||
| // case "days" : | ||
| // result = result / (1000 * 60 * 60 * 24); | ||
| // break; | ||
| // } |
Comment on lines
+4
to
+5
| const startDateStr = '31 Jan 2022'; | ||
| const endDateStr = '03 Feb 2021'; |
Owner
There was a problem hiding this comment.
why do you need these variables?
| // break; | ||
| // } | ||
| console.log(unitDivisor[unit]); | ||
| } |
Owner
There was a problem hiding this comment.
what are you returning in this function?
| @@ -0,0 +1,24 @@ | |||
| function recursiveOddSumTo(number) { | |||
| if (number == 1) | |||
| return 1; | |||
Owner
There was a problem hiding this comment.
use the if with brackets ({, })
| if (number == 1) | ||
| return 1; | ||
| if (number % 2 == 1) | ||
| return (recursiveOddSumTo(number - 1) + number); |
Owner
There was a problem hiding this comment.
move the main logic as a default return of the function
Comment on lines
+2
to
+8
| const result = {}; | ||
| for (const [key, value] of Object.entries(data)) { | ||
| result[key.toLowerCase()] = parseFloat(value).toFixed(2); | ||
|
|
||
| } | ||
|
|
||
| return result; |
Owner
There was a problem hiding this comment.
Let's use the Array.reduce method here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

No description provided.